home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Scrollbar.java < prev    next >
Text File  |  1998-09-22  |  27KB  |  756 lines

  1. /*
  2.  * @(#)Scrollbar.java    1.55 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.peer.ScrollbarPeer;
  17. import java.awt.event.*;
  18. import java.io.ObjectOutputStream;
  19. import java.io.ObjectInputStream;
  20. import java.io.IOException;
  21.  
  22.  
  23. /**
  24.  * The <code>Scrollbar</code> class embodies a scroll bar, a 
  25.  * familiar user-interface object. A scroll bar provides a 
  26.  * convenient means for allowing a user to select from a 
  27.  * range of values. The following three vertical
  28.  * scroll bars could be used as slider controls to pick 
  29.  * the red, green, and blue components of a color:
  30.  * <p>
  31.  * <img src="images-awt/Scrollbar-1.gif"
  32.  * ALIGN=center HSPACE=10 VSPACE=7> 
  33.  * <p>
  34.  * Each scroll bar in this example could be created with 
  35.  * code similar to the following: 
  36.  * <p>
  37.  * <hr><blockquote><pre>
  38.  * redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
  39.  * add(redSlider);
  40.  * </pre></blockquote><hr>
  41.  * <p>
  42.  * Alternatively, a scroll bar can represent a range of values. For 
  43.  * example, if a scroll bar is used for scrolling through text, the 
  44.  * width of the "bubble" or "thumb" can represent the amount of text 
  45.  * that is visible. Here is an example of a scroll bar that 
  46.  * represents a range:
  47.  * <p>
  48.  * <img src="images-awt/Scrollbar-2.gif" 
  49.  * ALIGN=center HSPACE=10 VSPACE=7> 
  50.  * <p>
  51.  * The value range represented by the bubble is the <em>visible</em> 
  52.  * range of the scroll bar. The horizontal scroll bar in this 
  53.  * example could be created with code like the following: 
  54.  * <p>
  55.  * <hr><blockquote><pre>
  56.  * ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 64, 0, 255);
  57.  * add(ranger);
  58.  * </pre></blockquote><hr>
  59.  * <p>
  60.  * Note that the maximum value above, 255, is the maximum value for 
  61.  * the scroll bar's bubble. The actual width of the 
  62.  * scroll bar's track is 255 + 64. When the scroll bar
  63.  * is set to its maximum value, the left side of the bubble
  64.  * is at 255, and the right side is at 255 + 64.
  65.  * <p>
  66.  * Normally, the user changes the value of the scroll bar by 
  67.  * making a gesture with the mouse. For example, the user can
  68.  * drag the scroll bar's bubble up and down, or click in the 
  69.  * scroll bar's unit increment or block increment areas. Keyboard
  70.  * gestures can also be mapped to the scroll bar. By convention,
  71.  * the <b>Page Up</b> and <b>Page Down</b> 
  72.  * keys are equivalent to clicking in the scroll bar's block
  73.  * increment and block decrement areas.
  74.  * <p>
  75.  * When the user changes the value of the scroll bar, the scroll bar
  76.  * receives an instance of <code>AdjustmentEvent</code>. 
  77.  * The scroll bar processes this event, passing it along to 
  78.  * any registered listeners. 
  79.  * <p>
  80.  * Any object that wishes to be notified of changes to the 
  81.  * scroll bar's value should implement 
  82.  * <code>AdjustmentListener</code>, an interface defined in
  83.  * the package <code>java.awt.event</code>. 
  84.  * Listeners can be added and removed dynamically by calling 
  85.  * the methods <code>addAdjustmentListener</code> and
  86.  * <code>removeAdjustmentListener</code>.
  87.  * <p>
  88.  * The <code>AdjustmentEvent</code> class defines five types 
  89.  * of adjustment event, listed here: 
  90.  * <p>
  91.  * <ul>
  92.  * <li><code>AdjustmentEvent.TRACK</code> is sent out when the 
  93.  * user drags the scroll bar's bubble.
  94.  * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> is sent out
  95.  * when the user clicks in the left arrow of a horizontal scroll 
  96.  * bar, or the top arrow of a vertical scroll bar, or makes the 
  97.  * equivalent gesture from the keyboard.
  98.  * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> is sent out
  99.  * when the user clicks in the right arrow of a horizontal scroll 
  100.  * bar, or the bottom arrow of a vertical scroll bar, or makes the 
  101.  * equivalent gesture from the keyboard.
  102.  * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> is sent out
  103.  * when the user clicks in the track, to the left of the bubble
  104.  * on a horizontal scroll bar, or above the bubble on a vertical
  105.  * scroll bar. By convention, the <b>Page Up</b> 
  106.  * key is equivalent, if the user is using a keyboard that 
  107.  * defines a <b>Page Up</b> key.
  108.  * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> is sent out
  109.  * when the user clicks in the track, to the right of the bubble
  110.  * on a horizontal scroll bar, or below the bubble on a vertical
  111.  * scroll bar. By convention, the <b>Page Down</b> 
  112.  * key is equivalent, if the user is using a keyboard that 
  113.  * defines a <b>Page Down</b> key.
  114.  * </ul>
  115.  * <p>
  116.  * The JDK 1.0 event system is supported for backwards
  117.  * compatibility, but its use with newer versions of JDK is 
  118.  * discouraged. The fives types of adjustment event introduced
  119.  * with JDK 1.1 correspond to the five event types 
  120.  * that are associated with scroll bars in previous JDK versions.
  121.  * The following list gives the adjustment event type, 
  122.  * and the corresponding JDK 1.0 event type it replaces.
  123.  * <p>
  124.  * <ul>
  125.  * <li><code>AdjustmentEvent.TRACK</code> replaces 
  126.  * <code>Event.SCROLL_ABSOLUTE</code>
  127.  * <li><code>AdjustmentEvent.UNIT_INCREMENT</code> replaces 
  128.  * <code>Event.SCROLL_LINE_UP</code>
  129.  * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> replaces 
  130.  * <code>Event.SCROLL_LINE_DOWN</code>
  131.  * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> replaces 
  132.  * <code>Event.SCROLL_PAGE_UP</code>
  133.  * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> replaces 
  134.  * <code>Event.SCROLL_PAGE_DOWN</code>
  135.  * </ul>
  136.  * <p>
  137.  *
  138.  * @version    1.55 07/01/98
  139.  * @author     Sami Shaio
  140.  * @see         java.awt.event.AdjustmentEvent
  141.  * @see         java.awt.event.AdjustmentListener
  142.  * @since       JDK1.0
  143.  */
  144. public class Scrollbar extends Component implements Adjustable {
  145.   
  146.     /**
  147.      * A constant that indicates a horizontal scroll bar.
  148.      * @since     JDK1.0
  149.      */
  150.     public static final int    HORIZONTAL = 0;
  151.  
  152.     /**
  153.      * A constant that indicates a vertical scroll bar.
  154.      * @since     JDK1.0
  155.      */
  156.     public static final int    VERTICAL   = 1;
  157.  
  158.     /**
  159.      * The value of the Scrollbar.
  160.      */
  161.     int    value;
  162.  
  163.     /**
  164.      * The maximum value of the Scrollbar.
  165.      */
  166.     int    maximum;
  167.  
  168.     /**
  169.      * The minimum value of the Scrollbar.
  170.      */
  171.     int    minimum;
  172.  
  173.     /**
  174.      * The size of the visible portion of the Scrollbar.
  175.      */
  176.     int    visibleAmount;
  177.  
  178.     /**
  179.      * The Scrollbar's orientation--being either horizontal or vertical.
  180.      */
  181.     int    orientation;
  182.  
  183.     /**
  184.      * The amount by which the scrollbar value will change when going
  185.      * up or down by a line.
  186.      */
  187.     int lineIncrement = 1;
  188.  
  189.     /**
  190.      * The amount by which the scrollbar value will change when going
  191.      * up or down by a page.
  192.      */
  193.     int pageIncrement = 10;
  194.  
  195.     transient AdjustmentListener adjustmentListener;
  196.  
  197.     private static final String base = "scrollbar";
  198.     private static int nameCounter = 0;
  199.     
  200.     /*
  201.      * JDK 1.1 serialVersionUID 
  202.      */
  203.     private static final long serialVersionUID = 8451667562882310543L;
  204.  
  205.     /**
  206.      * Constructs a new vertical scroll bar.
  207.      * @since   JDK1.0
  208.      */
  209.     public Scrollbar() {
  210.     this(VERTICAL, 0, 10, 0, 100);
  211.     }
  212.  
  213.     /**
  214.      * Constructs a new scroll bar with the specified orientation.
  215.      * <p>
  216.      * The <code>orientation</code> argument must take one of the two 
  217.      * values <code>Scrollbar.HORIZONTAL</code>, 
  218.      * or <code>Scrollbar.VERTICAL</code>, 
  219.      * indicating a horizontal or vertical scroll bar, respectively. 
  220.      * @param       orientation   indicates the orientation of the scroll bar.
  221.      * @exception   IllegalArgumentException    when an illegal value for
  222.      *                    the <code>orientation</code> argument is supplied.
  223.      * @since       JDK1.0
  224.      */
  225.     public Scrollbar(int orientation) {
  226.         this(orientation, 0, 10, 0, 100);
  227.     }
  228.  
  229.     /**
  230.      * Constructs a new scroll bar with the specified orientation, 
  231.      * initial value, page size, and minimum and maximum values. 
  232.      * <p>
  233.      * The <code>orientation</code> argument must take one of the two 
  234.      * values <code>Scrollbar.HORIZONTAL</code>, 
  235.      * or <code>Scrollbar.VERTICAL</code>, 
  236.      * indicating a horizontal or vertical scroll bar, respectively. 
  237.      * <p>
  238.      * If the specified maximum value is less than the minimum value, it 
  239.      * is changed to be the same as the minimum value. If the initial 
  240.      * value is lower than the minimum value, it is changed to be the 
  241.      * minimum value; if it is greater than the maximum value, it is 
  242.      * changed to be the maximum value. 
  243.      * @param     orientation   indicates the orientation of the scroll bar.
  244.      * @param     value     the initial value of the scroll bar.
  245.      * @param     visible   the size of the scroll bar's bubble, representing
  246.      *                      the visible portion; the scroll bar uses this 
  247.                             value when paging up or down by a page.
  248.      * @param     minimum   the minimum value of the scroll bar.
  249.      * @param     maximum   the maximum value of the scroll bar.
  250.      * @since     JDK1.0
  251.      */
  252.     public Scrollbar(int orientation, int value, int visible, int minimum, int maximum) {
  253.     switch (orientation) {
  254.       case HORIZONTAL:
  255.       case VERTICAL:
  256.         this.orientation = orientation;
  257.         break;
  258.       default:
  259.         throw new IllegalArgumentException("illegal scrollbar orientation");
  260.     }
  261.     setValues(value, visible, minimum, maximum);
  262.     }
  263.  
  264.     /**
  265.      * Construct a name for this component.  Called by getName() when the
  266.      * name is null.
  267.      */
  268.     String constructComponentName() {
  269.         return base + nameCounter++;
  270.     }
  271.  
  272.     /**
  273.      * Creates the Scrollbar's peer.  The peer allows you to modify
  274.      * the appearance of the Scrollbar without changing any of its
  275.      * functionality.
  276.      */
  277.  
  278.     public void addNotify() {
  279.       synchronized (getTreeLock()) {
  280.       if (peer == null)
  281.         peer = getToolkit().createScrollbar(this);
  282.     super.addNotify();
  283.       }
  284.     }
  285.  
  286.     /**
  287.      * Determines the orientation of this scroll bar. 
  288.      * @return    the orientation of this scroll bar, either 
  289.      *               <code>Scrollbar.HORIZONTAL</code> or 
  290.      *               <code>Scrollbar.VERTICAL</code>.
  291.      * @see       java.awt.Scrollbar#setOrientation
  292.      * @since     JDK1.0
  293.      */
  294.     public int getOrientation() {
  295.     return orientation;
  296.     }
  297.  
  298.     /**
  299.      * Sets the orientation for this scroll bar. 
  300.      * @param     the orientation of this scroll bar, either 
  301.      *               <code>Scrollbar.HORIZONTAL</code> or 
  302.      *               <code>Scrollbar.VERTICAL</code>.
  303.      * @see       java.awt.Scrollbar#getOrientation
  304.      * @exception   IllegalArgumentException  if the value supplied
  305.      *                   for <code>orientation</code> is not a
  306.      *                   legal value.
  307.      * @since     JDK1.1
  308.      */
  309.     public void setOrientation(int orientation) {
  310.     synchronized (getTreeLock()) {
  311.         if (orientation == this.orientation) {
  312.             return;
  313.         }
  314.         switch (orientation) {
  315.             case HORIZONTAL:
  316.             case VERTICAL:
  317.                 this.orientation = orientation;
  318.                 break;
  319.             default:
  320.                 throw new IllegalArgumentException("illegal scrollbar orientation");
  321.         }
  322.         /* Create a new peer with the specified orientation. */
  323.         if (peer != null) {
  324.         removeNotify();
  325.         addNotify();
  326.         invalidate();
  327.         }
  328.     }
  329.     }
  330.  
  331.     /**
  332.      * Gets the current value of this scroll bar.
  333.      * @return      the current value of this scroll bar.
  334.      * @see         java.awt.Scrollbar#getMinimum
  335.      * @see         java.awt.Scrollbar#getMaximum
  336.      * @since       JDK1.0
  337.      */
  338.     public int getValue() {
  339.     return value;
  340.     }
  341.  
  342.     /**
  343.      * Sets the value of this scroll bar to the specified value.
  344.      * <p>
  345.      * If the value supplied is less than the current minimum or 
  346.      * greater than the current maximum, then one of those values
  347.      * is substituted, as appropriate.
  348.      * <p>
  349.      * Normally, a program should change a scroll bar's  
  350.      * value only by calling <code>setValues</code>. 
  351.      * The <code>setValues</code> method simultaneously 
  352.      * and synchronously sets the minimum, maximum, visible amount, 
  353.      * and value properties of a scroll bar, so that they are 
  354.      * mutually consistent.
  355.      * @param       newValue   the new value of the scroll bar. 
  356.      * @see         java.awt.Scrollbar#setValues
  357.      * @see         java.awt.Scrollbar#getValue
  358.      * @see         java.awt.Scrollbar#getMinimum
  359.      * @see         java.awt.Scrollbar#getMaximum
  360.      * @since       JDK1.0
  361.      */
  362.     public void setValue(int newValue) {
  363.     /* Use setValues so that a consistent policy
  364.          * relating minimum, maximum, and value is enforced.
  365.          */
  366.         setValues(newValue, visibleAmount, minimum, maximum);
  367.     }
  368.  
  369.     /**
  370.      * Gets the minimum value of this scroll bar.
  371.      * @return      the minimum value of this scroll bar.
  372.      * @see         java.awt.Scrollbar#getValue
  373.      * @see         java.awt.Scrollbar#getMaximum
  374.      * @since       JDK1.0
  375.      */
  376.     public int getMinimum() {
  377.     return minimum;
  378.     }
  379.  
  380.     /**
  381.      * Sets the minimum value of this scroll bar.
  382.      * <p>
  383.      * Normally, a program should change a scroll bar's minimum 
  384.      * value only by calling <code>setValues</code>. 
  385.      * The <code>setValues</code> method simultaneously 
  386.      * and synchronously sets the minimum, maximum, visible amount, 
  387.      * and value properties of a scroll bar, so that they are 
  388.      * mutually consistent.
  389.      * @param       newMinimum   the new minimum value  
  390.      *                     for this scroll bar.
  391.      * @see         java.awt.Scrollbar#setValues
  392.      * @see         java.awt.Scrollbar#setMaximum
  393.      * @since       JDK1.1
  394.      */
  395.     public void setMinimum(int newMinimum) {
  396.     /* Use setValues so that a consistent policy
  397.          * relating minimum, maximum, and value is enforced.
  398.          */
  399.     setValues(value, visibleAmount, newMinimum, maximum);
  400.     }
  401.  
  402.     /**
  403.      * Gets the maximum value of this scroll bar.
  404.      * @return      the maximum value of this scroll bar.
  405.      * @see         java.awt.Scrollbar#getValue
  406.      * @see         java.awt.Scrollbar#getMinimum
  407.      * @since       JDK1.0
  408.      */
  409.     public int getMaximum() {
  410.     return maximum;
  411.     }
  412.  
  413.     /**
  414.      * Sets the maximum value of this scroll bar.
  415.      * <p>
  416.      * Normally, a program should change a scroll bar's maximum 
  417.      * value only by calling <code>setValues</code>. 
  418.      * The <code>setValues</code> method simultaneously 
  419.      * and synchronously sets the minimum, maximum, visible amount, 
  420.      * and value properties of a scroll bar, so that they are 
  421.      * mutually consistent.
  422.      * @param       newMaximum   the new maximum value  
  423.      *                     for this scroll bar.
  424.      * @see         java.awtScrollbar#setValues
  425.      * @see         java.awtScrollbar#setMinimum
  426.      * @since       JDK1.1
  427.      */
  428.     public void setMaximum(int newMaximum) {
  429.     /* Use setValues so that a consistent policy
  430.          * relating minimum, maximum, and value is enforced.
  431.          */
  432.         setValues(value, visibleAmount, minimum, newMaximum);
  433.     }
  434.  
  435.     /**
  436.      * Gets the visible amount of this scroll bar.
  437.      * <p>
  438.      * The visible amount of a scroll bar is the range of 
  439.      * values represented by the width of the scroll bar's 
  440.      * bubble. It is used to determine the scroll bar's 
  441.      * block increment.
  442.      * @return      the visible amount of this scroll bar.
  443.      * @see         java.awt.Scrollbar#setVisibleAmount
  444.      * @since       JDK1.1
  445.      */
  446.     public int getVisibleAmount() {
  447.     return getVisible();
  448.     }
  449.  
  450.     /**
  451.      * @deprecated As of JDK version 1.1,
  452.      * replaced by <code>getVisibleAmount()</code>.
  453.      */
  454.     public int getVisible() {
  455.     return visibleAmount;
  456.     }
  457.  
  458.     /**
  459.      * Sets the visible amount of this scroll bar.
  460.      * <p>
  461.      * The visible amount of a scroll bar is the range of 
  462.      * values represented by the width of the scroll bar's 
  463.      * bubble. It is used to determine the scroll bar's 
  464.      * block increment.
  465.      * <p>
  466.      * Normally, a program should change a scroll bar's  
  467.      * value only by calling <code>setValues</code>. 
  468.      * The <code>setValues</code> method simultaneously 
  469.      * and synchronously sets the minimum, maximum, visible amount, 
  470.      * and value properties of a scroll bar, so that they are 
  471.      * mutually consistent.
  472.      * @param       newAmount the amount visible per page.
  473.      * @see         java.awt.Scrollbar#getVisibleAmount
  474.      * @see         java.awt.Scrollbar#setValues
  475.      * @since       JDK1.1
  476.      */
  477.     public void setVisibleAmount(int newAmount) {
  478.         setValues(value, newAmount, minimum, maximum);
  479.     }
  480.  
  481.     /**
  482.      * Sets the unit increment for this scroll bar. 
  483.      * <p>
  484.      * The unit increment is the value that is added (subtracted) 
  485.      * when the user activates the unit increment area of the 
  486.      * scroll bar, generally through a mouse or keyboard gesture
  487.      * that the scroll bar receives as an adjustment event.
  488.      * @param        v  the amount by which to increment or decrement
  489.      *                         the scroll bar's value.
  490.      * @see          java.awt.Scrollbar#getUnitIncrement
  491.      * @since        JDK1.1
  492.      */
  493.     public void setUnitIncrement(int v) {
  494.     setLineIncrement(v);
  495.     }
  496.  
  497.     /**
  498.      * @deprecated As of JDK version 1.1,
  499.      * replaced by <code>setUnitIncrement(int)</code>.
  500.      */
  501.     public synchronized void setLineIncrement(int v) {
  502.     lineIncrement = v;
  503.     ScrollbarPeer peer = (ScrollbarPeer)this.peer;
  504.     if (peer != null) {
  505.         peer.setLineIncrement(v);
  506.     }
  507.     }
  508.  
  509.     /**
  510.      * Gets the unit increment for this scrollbar.
  511.      * <p>
  512.      * The unit increment is the value that is added (subtracted) 
  513.      * when the user activates the unit increment area of the 
  514.      * scroll bar, generally through a mouse or keyboard gesture
  515.      * that the scroll bar receives as an adjustment event.
  516.      * @return      the unit increment of this scroll bar.
  517.      * @see         java.awt.Scrollbar#setUnitIncrement
  518.      * @since       JDK1.1
  519.      */
  520.     public int getUnitIncrement() {
  521.     return getLineIncrement();
  522.     }
  523.  
  524.     /**
  525.      * @deprecated As of JDK version 1.1,
  526.      * replaced by <code>getUnitIncrement()</code>.
  527.      */
  528.     public int getLineIncrement() {
  529.     return lineIncrement;
  530.     }
  531.  
  532.     /**
  533.      * Sets the block increment for this scroll bar. 
  534.      * <p>
  535.      * The block increment is the value that is added (subtracted) 
  536.      * when the user activates the block increment area of the 
  537.      * scroll bar, generally through a mouse or keyboard gesture
  538.      * that the scroll bar receives as an adjustment event.
  539.      * @param        v  the amount by which to increment or decrement
  540.      *                         the scroll bar's value.
  541.      * @see          java.awt.Scrollbar#getBlockIncrement
  542.      * @since        JDK1.1
  543.      */
  544.     public void setBlockIncrement(int v) {
  545.     setPageIncrement(v);
  546.     }
  547.  
  548.     /**
  549.      * @deprecated As of JDK version 1.1,
  550.      * replaced by <code>setBlockIncrement()</code>.
  551.      */
  552.     public synchronized void setPageIncrement(int v) {
  553.     pageIncrement = v;
  554.     ScrollbarPeer peer = (ScrollbarPeer)this.peer;
  555.     if (peer != null) {
  556.         peer.setPageIncrement(v);
  557.     }
  558.     }
  559.  
  560.     /**
  561.      * Gets the block increment of this scroll bar.
  562.      * <p>
  563.      * The block increment is the value that is added (subtracted) 
  564.      * when the user activates the block increment area of the 
  565.      * scroll bar, generally through a mouse or keyboard gesture
  566.      * that the scroll bar receives as an adjustment event.
  567.      * @return      the block increment of this scroll bar.
  568.      * @see         java.awt.Scrollbar#setBlockIncrement
  569.      * @since       JDK1.1
  570.      */
  571.     public int getBlockIncrement() {
  572.     return getPageIncrement();
  573.     }
  574.  
  575.     /**
  576.      * @deprecated As of JDK version 1.1,
  577.      * replaced by <code>getBlockIncrement()</code>.
  578.      */
  579.     public int getPageIncrement() {
  580.     return pageIncrement;
  581.     }
  582.  
  583.     /**
  584.      * Sets the values of four properties for this scroll bar.
  585.      * <p>
  586.      * This method simultaneously and synchronously sets the values 
  587.      * of four scroll bar properties, assuring that the values of
  588.      * these properties are mutually consistent. It enforces the 
  589.      * constraints that maximum cannot be less than minimum, and that 
  590.      * value cannot be less than the minimum or greater than the maximum.
  591.      * @param      value is the position in the current window.
  592.      * @param      visible is the amount visible per page.
  593.      * @param      minimum is the minimum value of the scroll bar.
  594.      * @param      maximum is the maximum value of the scroll bar.
  595.      * @since      JDK1.0
  596.      */
  597.     public synchronized void setValues(int value, int visible, int minimum, int maximum) {
  598.     if (maximum <= minimum) {
  599.         maximum = minimum + 1;
  600.     }
  601.     if (visible > maximum - minimum) {
  602.       visible = maximum - minimum;
  603.     }
  604.     if (visible < 1) {
  605.       visible = 1;
  606.     }
  607.     if (value < minimum) {
  608.         value = minimum;
  609.     }
  610.     if (value > maximum - visible) {
  611.         value = maximum - visible;
  612.     }
  613.  
  614.     this.value = value;
  615.     this.visibleAmount = visible;
  616.     this.minimum = minimum;
  617.     this.maximum = maximum;
  618.     ScrollbarPeer peer = (ScrollbarPeer)this.peer;
  619.     if (peer != null) {
  620.         peer.setValues(value, visibleAmount, minimum, maximum);
  621.     }
  622.     }
  623.  
  624.     /**
  625.      * Adds the specified adjustment listener to receive instances of 
  626.      * <code>AdjustmentEvent</code> from this scroll bar.
  627.      * @param        l the adjustment listener.
  628.      * @see          java.awt.event.AdjustmentEvent
  629.      * @see          java.awt.event.AdjustmentListener
  630.      * @see          java.awt.Scrollbar#removeAdjustmentListener
  631.      * @since        JDK1.1
  632.      */ 
  633.     public synchronized void addAdjustmentListener(AdjustmentListener l) {
  634.     adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
  635.         newEventsOnly = true;
  636.     }
  637.  
  638.     /**
  639.      * Removes the specified adjustment listener so that it no longer 
  640.      * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
  641.      * @param        l    the adjustment listener.
  642.      * @see          java.awt.event.AdjustmentEvent
  643.      * @see          java.awt.event.AdjustmentListener
  644.      * @see          java.awt.Scrollbar#addAdjustmentListener
  645.      * @since        JDK1.1
  646.      */ 
  647.     public synchronized void removeAdjustmentListener(AdjustmentListener l) {
  648.     adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
  649.     }
  650.  
  651.     // REMIND: remove when filtering is done at lower level
  652.     boolean eventEnabled(AWTEvent e) {
  653.         if (e.id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
  654.             if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 ||
  655.                 adjustmentListener != null) {
  656.                 return true;
  657.             } 
  658.             return false;
  659.         }
  660.         return super.eventEnabled(e);
  661.     }     
  662.  
  663.     /**
  664.      * Processes events on this scroll bar. If the event is an 
  665.      * instance of <code>AdjustmentEvent</code>, it invokes the 
  666.      * <code>processAdjustmentEvent</code> method. 
  667.      * Otherwise, it invokes its superclass's 
  668.      * <code>processEvent</code> method.
  669.      * @param        e the event.
  670.      * @see          java.awt.event.AdjustmentEvent
  671.      * @see          java.awt.Scrollbar#processAdjustmentEvent
  672.      * @since        JDK1.1
  673.      */
  674.     protected void processEvent(AWTEvent e) {
  675.         if (e instanceof AdjustmentEvent) {
  676.             processAdjustmentEvent((AdjustmentEvent)e);
  677.             return;
  678.         }
  679.     super.processEvent(e);
  680.     }
  681.  
  682.     /** 
  683.      * Processes adjustment events occurring on this 
  684.      * scrollbar by dispatching them to any registered 
  685.      * <code>AdjustmentListener</code> objects.
  686.      * <p>
  687.      * This method is not called unless adjustment events are 
  688.      * enabled for this component. Adjustment events are enabled 
  689.      * when one of the following occurs:
  690.      * <p><ul>
  691.      * <li>An <code>AdjustmentListener</code> object is registered 
  692.      * via <code>addAdjustmentListener</code>.
  693.      * <li>Adjustment events are enabled via <code>enableEvents</code>.
  694.      * </ul><p>
  695.      * @param       e the adjustment event.
  696.      * @see         java.awt.event.AdjustmentEvent
  697.      * @see         java.awt.event.AdjustmentListener
  698.      * @see         java.awt.Scrollbar#addAdjustmentListener
  699.      * @see         java.awt.Component#enableEvents
  700.      * @since       JDK1.1
  701.      */ 
  702.     protected void processAdjustmentEvent(AdjustmentEvent e) {
  703.         if (adjustmentListener != null) {
  704.             adjustmentListener.adjustmentValueChanged(e);
  705.         }
  706.     }
  707.  
  708.     /**
  709.      * Returns the parameter string representing the state of 
  710.      * this scroll bar. This string is useful for debugging.
  711.      * @return      the parameter string of this scroll bar.
  712.      * @since       JDK1.0
  713.      */
  714.     protected String paramString() {
  715.     return super.paramString() +
  716.         ",val=" + value +
  717.         ",vis=" + visibleAmount +
  718.         ",min=" + minimum +
  719.         ",max=" + maximum +
  720.         ((orientation == VERTICAL) ? ",vert" : ",horz");
  721.     }
  722.  
  723.  
  724.     /* Serialization support. 
  725.      */
  726.  
  727.     private int scrollbarSerializedDataVersion = 1;
  728.  
  729.     private void writeObject(ObjectOutputStream s)
  730.       throws IOException 
  731.     {
  732.       s.defaultWriteObject();
  733.  
  734.       AWTEventMulticaster.save(s, adjustmentListenerK, adjustmentListener);
  735.       s.writeObject(null);
  736.     }
  737.  
  738.     private void readObject(ObjectInputStream s)
  739.       throws ClassNotFoundException, IOException 
  740.     {
  741.       s.defaultReadObject();
  742.  
  743.       Object keyOrNull;
  744.       while(null != (keyOrNull = s.readObject())) {
  745.     String key = ((String)keyOrNull).intern();
  746.  
  747.     if (adjustmentListenerK == key) 
  748.       addAdjustmentListener((AdjustmentListener)(s.readObject()));
  749.  
  750.     else // skip value for unrecognized key
  751.       s.readObject();
  752.       }
  753.     }
  754.  
  755. }
  756.